/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2018-2021.
 * Description: support stat trace feature
 * Author: nixiaoming
 * Create: 2018-3-4
 */

#include <trace/rtos_tracepoint.h>

#ifdef CONFIG_RTOS
/* Define the tracepoint here, if the feature does not have its own c file */

#ifdef CONFIG_RTOS_MICROSTATE_ACCT
#include <linux/msa.h>
#ifdef CONFIG_RTOS_MICROSTATE_ACCT_ON_SYSTEM_CALL
DEFINE_TRACE(space_switch,
	TP_PROTO(enum msa_thread_state state),
	TP_ARGS(state));
#endif
DEFINE_TRACE(msa_irq_start,
	TP_PROTO(unsigned int irq, struct pt_regs *regs, void *pfunc),
	TP_ARGS(irq, regs, pfunc));
#endif

#ifdef CONFIG_RTOS_RSM_SIGBUS
DEFINE_TRACE(sigbus_debug,
		TP_PROTO(int ret,  void *fault, struct vm_area_struct *vma, struct vm_fault *vmf, void *reserve),
		TP_ARGS(ret, fault, vma, vmf, reserve));
EXPORT_TRACEPOINT_SYMBOL_GPL(sigbus_debug);
#endif /* CONFIG_RTOS_RSM_SIGBUS */

#ifdef CONFIG_RTOS_SIGNAL_HANDLE_TRACE
DEFINE_TRACE(sa_handler_reset,
		TP_PROTO(int sig, struct task_struct *t, enum SA_HANDLER_RESET_FLAG mode),
		TP_ARGS(sig, t, mode));
EXPORT_TRACEPOINT_SYMBOL(sa_handler_reset);
DEFINE_TRACE(sys_sigreturn_print,
		TP_PROTO(struct task_struct *t),
		TP_ARGS(t));
EXPORT_TRACEPOINT_SYMBOL(sys_sigreturn_print);
#endif /* CONFIG_RTOS_SIGNAL_HANDLE_TRACE */

#ifdef CONFIG_RTOS_TTY_STATUS_TRACE
#include <linux/tty.h>
DEFINE_TRACE(tty_status,
	     TP_PROTO(struct tty_struct *tty,
		      unsigned long stopped,
		      void *func),
	     TP_ARGS(tty, stopped, func));
EXPORT_TRACEPOINT_SYMBOL_GPL(tty_status);
#endif

#ifdef CONFIG_RTOS_HAL_ENABLE_UART_RX_SWITCH
#ifdef CONFIG_TRACEPOINTS
DEFINE_TRACE(uart_insert_char,
		TP_PROTO(struct uart_rx_args *args),
		TP_ARGS(args));
EXPORT_TRACEPOINT_SYMBOL_GPL(uart_insert_char);
#else
static ATOMIC_NOTIFIER_HEAD(enable_uart_rx_chain);
int trace_uart_insert_char(struct uart_rx_args *args)
{
	return atomic_notifier_call_chain(&enable_uart_rx_chain, 0, args);
}

int register_trace_uart_insert_char(struct notifier_block *nb)
{
	return atomic_notifier_chain_register(&enable_uart_rx_chain, nb);
}
EXPORT_SYMBOL_GPL(register_trace_uart_insert_char);

int unregister_trace_uart_insert_char(struct notifier_block *nb)
{
	return atomic_notifier_chain_unregister(&enable_uart_rx_chain, nb);
}
EXPORT_SYMBOL_GPL(unregister_trace_uart_insert_char);
#endif
#endif

#ifdef CONFIG_RTOS_TRACE_SENDMSG
DEFINE_TRACE(sendmsg,
	TP_PROTO(struct socket *sock, struct msghdr *msg, size_t len),
	TP_ARGS(sock, msg, len));
EXPORT_TRACEPOINT_SYMBOL(sendmsg);
#endif

#ifdef CONFIG_RTOS_SKB_MEMLEAK_DFX
DEFINE_TRACE(kmem_cache_free_bulk,
	TP_PROTO(unsigned long call_site, struct kmem_cache *s, void **ptr, size_t size),
	TP_ARGS(call_site, s, ptr, size));
EXPORT_TRACEPOINT_SYMBOL(kmem_cache_free_bulk);
#endif

#endif
